package com.nbot.common.command;

import java.io.Serializable;
import java.util.Date;

/**
 * b 和 s 之间的指令
 */
public abstract class BaseCommand implements Serializable, BotCommand, Comparable<BaseCommand> {
    private static final long serialVersionUID = -213339643663003200L;
    /**
     * 指令类型，类型的值越小，优先级越高
     */
    private int type;
    /**
     * 指令生成日期
     */
    private Date date;

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    /**
     * 优先度，在类型相同的情况下，优先度（priority）越小，优先级越高
     */
    private int priority = 1;

    public BaseCommand() {
        this.date = new Date();
    }

    public BaseCommand(int type) {
        this.type = type;


    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "BaseCommand{" +
                "type=" + type +
                ", date=" + date +
                ", priority=" + priority +
                '}';
    }

    /**
     * 用于在PriorityBlockingQueue队列中，判断优先级
     * 比较类型type和优先度priority，两者的乘积越小，优先级越高
     * @param o
     * @return
     */
    @Override
    public int compareTo(BaseCommand o) {
        return this.priority * this.type < o.priority * this.type ? 1
                : this.priority * this.type > o.priority * this.type ? -1 : 0;
    }
}
